<%@page contentType="text/html; charset=UTF-8" language="java" %>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-html"  prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-bean"  prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://displaytag.sf.net" 			 prefix="display" %>
<%@page import="com.kcs.common.utils.commonUtils"%>
<%@page import="com.kcs.common.utils.PropsUtils"%>
<%@page import="com.kcs.common.utils.Constant"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
<title>Daily Report</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript" src="jsp/script/jquery/plugin/fancybox/jquery.easing-1.3.pack.js"></script>
<script type="text/javascript" src="jsp/script/jquery/plugin/fancybox/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="jsp/script/jquery/plugin/fancybox/jquery.fancybox-1.3.4.pack.js"></script>   
<script type="text/javascript" src="jsp/script/jsDatePick.full.1.3.js"></script>   	
<script type="text/javascript" src="jsp/script/common.js"></script>  
<link rel="stylesheet" type="text/css" href="jsp/script/jquery/plugin/fancybox/jquery.fancybox-1.3.4.css"/>
<link rel="stylesheet" type="text/css" href="jsp/css/table.css"/>
<link rel="stylesheet" type="text/css" href="jsp/css/jsDatePick_ltr.css" />
<link rel="stylesheet" type="text/css" href="jsp/css/fxmarginStyle.css"/>
<script type="text/javascript">

	$(document).ready(function() {
		jQuery("#action").val("init");
		var status = jQuery("#status").val();

		if (status == "N") jQuery("#normal").click();
		else if (status == "O") jQuery("#over").click();
		else jQuery("#all").click();

		new JsDatePick({
			useMode:2,
			target:"asOfDate",
			dateFormat:"%d/%m/%Y"
		});

		analystDataTable();
	});	

	function analystDataTable(){
		var tr 		= jQuery("#data tr");
		var limit 	= 0;

		for(var i = 1 ; i < tr.length ; i++){
			tr.get(i).id = "tr_no_" + i;
		}

		for(var i = 1 ; i < tr.length ; i++){
			limit = parseFloat(jQuery("#tr_no_" + i + " td").get(11).innerHTML);

			if(limit < 0){
				jQuery("#tr_no_" + i + " td").css('color','red');
			}
		}
	}
			
	function resetFunction(){
		loading();
		jQuery("#action").val("init");
		submitform();
	}
	
	function search(){
		loading();
		jQuery("#action").val("search");
		submitform();
	}
	
	// for popup customer //
	function onPopup(id, src, width, height){
		g_datacustomer = null;
		jQuery("#" + id + "_iframe").html("");
		src = "http://" + window.location.host + "/FxMargin/" + src + ".do?pAction=init";
		var html = "<center><iframe src='" + src +"' height='" + height +"px' width='" + width + "px' id='myIframe'></iframe></center>";

		jQuery("#" + id + "_iframe").html(html);

		openPopup(id);
		
	}

	function select(data){
		g_datacustomer = data;
	}
	
	function onCustomer(){
		if(g_datacustomer != null){
			jQuery("[name=cifNo]").val(g_datacustomer.cifNo);
	 		jQuery("[name=customerName]").val(g_datacustomer.customerName);	
	 		jQuery.fancybox.close();
		}
	}
	
	function offCustomer(){
		jQuery.fancybox.close();		
	}
	// for popup customer //
	
	function onChangeStatus(value){
		jQuery("#status").val(value);
	}

	function exportExcel(){
		jQuery("#action").val("export");
		submitform();
	}
	
</script>
</head>
<body>

<%@ include	file="include/headerMenu.jsp"%>

<center>
<div style="width:95%" align="center">
	<html:form action="/DailyReportAction.do">
		<html:hidden property="action" styleId="action"/>
		
		<table width="100%" class="MarginHeader">
			<tr>
				<td align="left">Daily Report</td>
			</tr>
		</table>
		
		<div class="CriteriaBox">
			<table width="100%" class="MarginCriteria">
				<tr>
					<td align="right">CIF No. :</td>
					<td align="left" >
						<html:text property="cifNo" readonly="true" styleClass="disabled"></html:text>
					</td>
					<td align="right">Customer Name :</td>
					<td align="left" >
						<html:text property="customerName" readonly="true" styleClass="disabled"></html:text>
						<img src="jsp/images/btn/glass_search.gif" style="width:30px;cursor:pointer;" onclick="onPopup('popupCustomer','PopupCustomerAction',700,540);" />
					</td>
				</tr>
				<tr>
					<td align="right">As of Date :</td>
					<td align="left" >
						<html:text property="asOfDate" styleId="asOfDate" readonly="true"></html:text>
					</td>
					<td align="right">Status :</td>
					<td align="left" >
						<html:hidden property="status" styleId="status"/>
						<input type="radio" name="radio_status" onchange="onChangeStatus('A');" id="all" value="ALL" checked="checked"/> All &nbsp;
						<input type="radio" name="radio_status" onchange="onChangeStatus('N');" id="normal" value="N"/> Normal &nbsp;
						<input type="radio" name="radio_status" onchange="onChangeStatus('O');" id="over" value="O"/> Over &nbsp;
					</td>
				</tr>
			</table>
			
			<table width="100%" class="MarginCriteria">
				<tr>
					<td width="100%" align="center">
						<input type="button" class="button" value="Search" onclick="search();"/>
						&nbsp;&nbsp;
						<input type="button" class="button" value="Reset" onclick="resetFunction();"/>
					</td>
				</tr>
			</table>
			
		</div>
		
		<logic:present name="<%=Constant.SHOW_RESULT%>">
			<div class="MarginTable">
				<display:table id="data" name="sessionScope.DailyReportActionForm.dailyReportList" requestURI="/DailyReportAction.do" pagesize="10" >
					
					<display:column property="rowNum"			title="No" 				sortable="false" class="center"/>
					<display:column property="cifNo"   			title="CIF No."   		sortable="false" class="center"/>
					<display:column property="customerName" 	title="Customer Name" 	sortable="false" class="left"/>				
					<display:column property="cashBalance" 		title="Cash Balance" 	sortable="false" class="right" format="{0,number,#,##0.00}"/>		
					<display:column property="realizedPL"		title="Realized P/L" 	sortable="false" class="right" format="{0,number,#,##0.00}"/>		
					<display:column property="unRealzedPL" 		title="Unrealized P/L" 	sortable="false" class="right" format="{0,number,#,##0.00}"/>		
					<display:column property="equityBalance" 	title="Equity Balance" 	sortable="false" class="right" format="{0,number,#,##0.00}"/>
					<display:column property="imRequired" 		title="IM Required" 	sortable="false" class="right" format="{0,number,#,##0.00}"/>		
					<display:column property="excess" 			title="Excess" 			sortable="false" class="right" format="{0,number,#,##0.00}"/>		
					<display:column property="mmRequired"		title="MM Required" 	sortable="false" class="right" format="{0,number,#,##0.00}"/>		
					<display:column property="marginCall" 		title="Margin Call" 	sortable="false" class="right" format="{0,number,#,##0.00}"/>		
					<display:column property="limit" 			title="Limit (THB)" 	sortable="false" class="right" format="{0,number,#,##0.00}"/>
					<display:column property="status" 			title="Status" 			sortable="false" class="center"/>
				</display:table>
			</div>
		</logic:present>
		
		<logic:present name="<%=Constant.NOT_EMPTY%>">
			<table width="100%">
				<tr>
					<td width="100%" align="center"><input type="button" class="button" value="Export Excel" onclick="exportExcel();"/></td>
				</tr>
			</table>
		</logic:present>
		
		<div style="display:none">
	        <div id="popupCustomer" style="width:710px;height: 600px">
	        	<div id="popupCustomer_iframe"></div>
				<table width="100%">
					<tr>
						<td width="33%" align="center">
							<input type="button" value="Ok" class="button" onclick="onCustomer();"/>
						</td>
						<td width="34%" align="center">
							<input type="button" value="Close" class="button" onclick="offCustomer();"/>
						</td>
					</tr>
				</table>
	        </div>
	    </div>
	    
		<%@ include	file="include/footer.jsp"%> 
		<%@ include	file="include/message.jsp"%> 
		
	</html:form>	
	
</div>
</center>

</body>
</html>